//  ========== 
//  = 点点安盈产品详情 业务JS = 
//  ========== 
var bidId ;
var Main = function(){
	if('false' === Util.requestURL('buyFlag')){
		$('.m-proj-footer').hide();
	}
	mui.init({
		swipeBack:true 		//启用右滑关闭功能
	});
	this.init();
};
Main.prototype = {
	init : function(){
		var _this = this;
		_this.tab();
		//加载数据
		_this.loadData();
		_this.eventInit();
		$('#item1mobile').height($('#item1mobile .mui-table-view').height());
	},
	tab: function() {
					var $win = $(window);
					var $scrollTo = $('#G-proj');
					var $slider = $('#slider');
					var $tab = $('#sliderSegmentedControl');
					var $tab_bar = $('#sliderProgressBar');
					$win.scroll(function() {
						var index = $tab.find('.mui-control-item.mui-active').index(); //当前显示tab索引
						if($win.scrollTop() >= ($scrollTo.height() - 1)) {
							$tab.addClass('nav-fixed');
							$tab_bar.addClass('nav-bar-fixed');
						} else {
							$tab.removeClass('nav-fixed');
							$tab_bar.removeClass('nav-bar-fixed');
						}
					})
			},
	eventInit : function(){//绑定事件
		        $('#G-go-buy').on('tap', function() {
		        	//判断是否登录
		        	if(!Util.checkLogin()){
		        			mui.openWindow({
								url:'login.html'
							})
		        	}else{
			        	if(!$(this).hasClass('m-btn-disabled')){
			        		mui.openWindow({
								url:'bidPlanConfirm.html?bidId='+bidId,
								id:'bidPlanConfirm'
							})
			        	}else{
			        		return false;
			        	}
		        	}
				});
	},

	//加载数据
	loadData : function(){
		bidId = Util.requestURL('bidId');
		var url = server_url + '/creditFlow/financingAgency/bidPlanDetailPlBidPlan.do';
		var param = {
					isMobile:1,
					bidId:bidId
				};
		var _formatStr = function(str){
			if(str==null || str == '' || str=='undefined'){
				str = '未填';
			}
			return str;
		}
		//加载数据
		$.getJSON(url,param,function(retData){
			
			var data = retData.data;
			if(data.state == '1'){
				$("#G-go-buy").removeClass('m-btn-disabled');
			}
			$(".m-bid-pro-name").html(data.bidProName);//产品名称
			if('1' == data.novice){//新标记
				$(".m-proj-tag-div").html('<span class="mui-h5 m-proj-tag tag-ble">新</span>');
			}
			if('1' == data.coupon){//券标记
				$(".m-proj-tag-div").html('<span class="mui-h5 m-proj-tag tag-yew">券</span>');
			}
			//年化收益
			$(".m-proj-lt .m-big").html(data.interestRate);
			if(data.addRate && data.addRate > 0){
			$(".m-proj-lt .m-small").html('+'+data.addRate);
			}
			//进度
			$('.z-act i').css('width',data.progress+'%');
			$('.z-act .m-range-round').css('left',data.progress+'%');
			//剩余期限
			$('.m-loan-life').html(data.loanLife);
			//可投金额
			$('.m-after-money').html(data.afterMoney);
			//总额
			$('.m-bid-money').html(data.bidMoney);
			//起投金额
			$('.m-start-money').html(data.startMoney+'元起');
			//项目编号
			$('.m-bid-pro-number').html(data.bidProNumber);
			//购买截止日期
			$('.m-bid-end-time').html(data.bidEndTime.substr(0,10));
			//用户名
			//$('.m-pd-user-name').html(_formatStr(data.bpPersionDirPro.userName));
			//年龄
			//$('.m-pd-age').html(_formatStr(data.bpPersionDirPro.age));
			//学历
			//$('.m-pd-education').html(_formatStr(data.bpPersionDirPro.education));
			//财务
			//$('.m-pd-main-finance').html(_formatStr(data.bpPersionDirPro.plPersionDirProKeep.mainFinance));
			//工作城市
			//$('.m-pd-work-city').html(_formatStr(data.bpPersionDirPro.workCity));
			//行业
			//$('.m-pd-hangye-name').html(_formatStr(data.bpPersionDirPro.plPersionDirProKeep.hangyeName));
			//项目描述
			$('.m-pd-pro-des').html(_formatStr(retData.proDes.proDes));
			//资金用途
			$('.m-pd-pro-use-way').html(_formatStr(retData.proDes.proUseWay));
			//还款来源
			$('.m-pd-pro-pay-money-way').html(_formatStr(retData.proDes.proPayMoneyWay));
			//项目描述
			$('.m-pd-pro-risk-ctr').html(_formatStr(retData.proDes.proRiskCtr));
			//安全保障
			//
			//	for(k in retData.listMaterials){
			//		$(".m-proj-list-materials").append('<li class="mui-table-view-cell"><img src=/></li>');
			//	}
			//}
			if(retData.listMaterials){
				for(k in retData.listMaterials){
					for(m in retData.listMaterials[k].fileFormList){
						var li = '<li class="mui-table-view-cell"><img class="m-material" data-preview-src="" data-preview-group="1"  src="../assets/img/60x60.gif" data-lazyload="'+server_url+'/'+retData.listMaterials[k].fileFormList[m].filepath+'"/></li>';
						$(".m-proj-list-materials").append(li);
					}
				}
				mui.previewImage();
			
			}
			var lazyLoadApi = mui(document).imageLazyload({
				placeholder: '../assets/img/60x60.gif',
				autoDestroy: false
			});
			//存储起投金额、递增金额、上限金额、可投金额
//			Util.setItem("startMoney",data.startMoney);//起投金额
//			Util.setItem("riseMoney",data.riseMoney);//递增金额
//			Util.setItem("limitMoney",data.maxMoney);//上限金额
//			Util.setItem("afterMoney",data.afterMoney);//可投金额

			document.getElementById('slider').addEventListener('slide', function(e) {
				if(e.detail.slideNumber == 1){
					console.log($('.m-proj-list-materials').height())
					$('#item2mobile').height($('.m-proj-list-materials').height());
					$('#item1mobile').height(300);
				}else{
					console.log($("#scroll1").height())
					$('#item1mobile').height($('.mui-table-view').height());
					$('#item2mobile').height(300);
				}
			})
		})
	}
	
}
